<!DOCTYPE HTML>
<html>
<head>
	<title>商品列表</title>
	<meta charset="utf-8">
	<link rel="stylesheet" type="text/css" href="static/assets/global/plugins/bootstrap/css/bootstrap.css" />
	<link rel="stylesheet" type="text/css" href="static/assets/global/css/components.css" />
	<link rel="stylesheet" type="text/css" href="static/assets/admin/pages/css/login.css" />
	<script type="text/javascript" src="static/assets/global/plugins/jquery-1.11.0.min.js"></script>
</head>
<body>
	<div class="content">
		<h3 class="form-title">商品列表</h3>
		<div class="table-responsive">
			<table class="table">
				<thead>
					<tr>
						<th>商品名</th>
						<th>商品图片</th>
						<th>商品描述</th>
						<th>商品价格</th>
						<th>商品库存</th>
						<th>商品销量</th>
					</tr>
				</thead>
				<tbody id="container"></tbody>
			</table>
		</div>
	</div>
</body>
<script type="text/javascript">
	var g_itemList = [];
	jQuery(document).ready(function(){
		$.ajax({type:"GET",
				url:"http://localhost:8081/miaosha/item/getItemList",
				xhrFields:{withCredentials: true},
				success:function(data){
					if(data.status == "success"){
						// window.location.href="login.html"
						g_itemList = data.data;
						relaodDom();
					}else{
						alert("获取商品列表失败："+data.data.errMsg);
					}
				},
				error:function(data){
					alert("获取商品列表失败："+data.responseText );
				}
			});
	});
	function relaodDom(){
		for(var i = 0;i<g_itemList.length;i++){
			var itemVo = g_itemList[i];
			var dom = "<tr data-id='"+itemVo.id+"' id='itemDetail"+itemVo.id+"'><td>"+itemVo.title+"</td><td><img style='width:100px;height:aotu;' src='"+itemVo.imgUrl+"'/></td><td>"+itemVo.description+"</td><td>"+itemVo.price+"</td><td>"+itemVo.stock+"</td><td>"+itemVo.sales+"</td></tr>";
			$("#container").append($(dom));
			$("#itemDetail"+itemVo.id).on("click",function(e){
				window.location.href = "promo.html?id="+$(this).data("id");
			});
		}
	}
</script>
</html>